
#include "sbAlbumService.h"
#include "sbAlbumViewScan.h"

#include <nsICategoryManager.h>
#include <nsIGenericFactory.h>
#include <nsServiceManagerUtils.h>

/*********************
 * sbIAlbumService
 ********************/
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(sbAlbumService, Initialize)

static NS_METHOD
sbAlbumServiceRegister(nsIComponentManager*         aCompMgr,
                       nsIFile*                     aPath,
                       const char*                  aLoaderStr,
                       const char*                  aType,
                       const nsModuleComponentInfo* aInfo)
{
  nsresult rv;

  // Get the category manager.
  nsCOMPtr<nsICategoryManager> categoryManager =
                                 do_GetService(NS_CATEGORYMANAGER_CONTRACTID,
                                               &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  // Add self to the app-startup category.
  rv = categoryManager->AddCategoryEntry
                          ("app-startup",
                           SB_ALBUMSERVICE_CLASSNAME,
                           "service," SB_ALBUMSERVICE_CONTRACTID,
                           PR_TRUE,
                           PR_TRUE,
                           nsnull);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}


static NS_METHOD
sbAlbumServiceUnregister(nsIComponentManager*         aCompMgr,
                         nsIFile*                     aPath,
                         const char*                  aLoaderStr,
                         const nsModuleComponentInfo* aInfo)
{
  nsresult rv;

  // Get the category manager.
  nsCOMPtr<nsICategoryManager> categoryManager =
                                 do_GetService(NS_CATEGORYMANAGER_CONTRACTID,
                                               &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  // Delete self from the app-startup category.
  rv = categoryManager->DeleteCategoryEntry("app-startup",
                                            SB_ALBUMSERVICE_CLASSNAME,
                                            PR_TRUE);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}

//------------------------------------------------------------------------------
//
// Songbird album view scan Component.
//
//------------------------------------------------------------------------------

// Construct the sbAlbumViewScan object
NS_GENERIC_FACTORY_CONSTRUCTOR(sbAlbumViewScan)


static nsModuleComponentInfo components[] =
{
  // Album Service component info.
  {
    SB_ALBUMSERVICE_CLASSNAME,
    SB_ALBUMSERVICE_CID,
    SB_ALBUMSERVICE_CONTRACTID,
    sbAlbumServiceConstructor,
    sbAlbumServiceRegister,
    sbAlbumServiceUnregister
  },
  // Album View Scan component info.
  {
    SB_ALBUMVIEWSCAN_CLASSNAME,
    SB_ALBUMVIEWSCAN_CID,
    SB_ALBUMVIEWSCAN_CONTRACTID,
    sbAlbumViewScanConstructor
  }
};

NS_IMPL_NSGETMODULE(albumServiceModule, components)
